Unprotect Excel Worksheet

Hello,

recently i started programming with DXL and i need some help.

My question is: Is it possible to unprotect a worksheet and then write in the cells something and then again protect the worksheet with dxl?

I used this code form the DXL Reference Manual:

string SetExcelCell(OleAutoObj objSheet,int xCellLoc,int yCellLoc,string property,string value)

{

OleAutoObj objCell = null

OleAutoArgs autoArgs = create

string result = null

// before getting the cell unprotect the worksheet with password

put(autoArgs, yCellLoc)

put(autoArgs, xCellLoc)

result = oleMethod(objSheet,"Cells",autoArgs, objCell)

if (result == null)

{

result = olePut(objCell, property, value)

}

return result

}

It is my first post. I am sorry if i have done mistakes or didn't explain my problem correctly. :)

Yours sincerely

Shariq

 

 


C.Shariq - Tue Nov 06 08:48:47 EST 2018

Re: Unprotect Excel Worksheet
O.Wilkop - Wed Nov 07 02:32:06 EST 2018

Yes, look at this example code:

OleAutoObj objExcel = oleGetAutoObject("Excel.Application");

OleAutoObj objSheet;
oleGet(objExcel, "ActiveSheet", objSheet);

OleAutoArgs args = create
put(args, "lalala");
oleMethod(objSheet, "Unprotect", args);

//stuff
clear(args);
put(args, 3); //3
put(args, 5); //B

OleAutoObj objCell;
oleGet(objSheet, "Cells", args, objCell);
olePut(objCell, "Value", "TestValue");


clear(args);
put(args, "DrawingObjects", "True");
put(args, "Contents", "True");
put(args, "Scenarios", "True");
put(args, "Password", "lalala");
//other options you want to protect

oleMethod(objSheet, "Protect", args);

It grabs the current open Excel, gets the ActiveSheet and unprotects it with the password "lalala". Afterwards it gets the cell at B3 and writes "TestValue" to it. Afterwards it protects the sheet again with the 3 options and the password "lalala" again.

 

Hope this helps you out, you'll have to adjust the code to use your sheet/columns/password/protectionoptions of course.

Re: Unprotect Excel Worksheet
C.Shariq - Wed Nov 07 03:28:23 EST 2018

Hey,

 

thanks a lot. That was exactly what I was looking for.

 

Best regards